﻿@model List<ByHand.Model.Order>
@{
    var tablename = "TableOrder";
    var cul = System.Globalization.CultureInfo.GetCultureInfo("vi-VN");
    //exclude last column command
    var numbercolumn = 8;
    var colsname = new[] { "#", "Khách hàng", "Sản phẩm", "SL", "Trạng Thái", "Mã QC", "Date", "Tổng" };
    var colsvalue = new[] { "Title", "ProductCode", "CreatedDate", "EndDate" };
    var curaction = "Index";
    var curcontroller = "Order";
    var configaction = new { details = "Details", del = "Del", create = "Create", undel = "UnDel", edit = "Edit" };
    var configtext = new { details = "Details", del = "Delete", create = "Create", undel = "Recovery", edit = "Edit" };
    var isfilter = ViewData["filter"] == null ? false : true;
    int status = -1;
    if (ViewData["status"] != null)
    {
        status = Convert.ToInt16(ViewData["status"]);
    }
    var total = Convert.ToInt32(ViewData["total"]);
    var curpage = Convert.ToInt32(ViewData["curpage"]);
    var valuesAsList = Enum.GetValues(typeof(ByHand.Services.Code.EOrderStatus)).Cast<ByHand.Services.Code.EOrderStatus>().ToList();
}
<div class="render-content">
    <div class="form-search" id="form-search" style="text-align: center; padding-bottom: 20px;">
        <input type="text" class="input-medium search-query" value="@(isfilter ? ViewData["filter"] : "")" id="inputsearch" style="display:inline;height:30px;width:400px;"/>
        Nhập thông tin cần tìm và enter
    </div>
    <div class="content table-partial-content">
        <ul class="nav nav-pills">
            <li class="@( status == -1 ? "active" : "")">
                <a href="/@curcontroller/@curaction/status/-1/pages/1/filter/@(isfilter ? ViewData["filter"] : "")">All</a>
            </li>
            @foreach (var item in valuesAsList)
            {
                <li class="@(status == (int)item ? "active" : "")"><a href="/@curcontroller/@curaction/status/@((int)item)/pages/1/filter/@(isfilter ? ViewData["filter"] : "")">@item.ToString().ToLower().Replace("order_", "")</a></li>
            }
        </ul>
        <table class="table table-hover sort table-bordered">
            <thead>
                <tr>
                    @for (int i = 0; i < numbercolumn; i++)
                    {
                        <th>@colsname[i]
                            <span style="float: right;"><i class="icon-sort"></i></span>
                        </th>
                    }
                </tr>
            </thead>
            <tbody>
                @foreach (var item in Model)
                {
                    <tr>
                        <td>
                            @item.ID
                        </td>
                        <td>
                            @item.Buyer
                        </td>
                        <td>
                            <a href="javascript:;" onclick="detail(@item.ID)">@item.Product.Title</a>
                        </td>
                        <td>
                            @item.Quantity
                        </td>
                        @*                    <td>
                        @{foreach (var i in item.OrderDetail)
                          {
                            <p>@(i.OptionsValue == "undefined" ? "" : i.OptionsValue.Replace("_", ": ").Replace("-", " ")) Số lượng: @i.Quantity</p>
                          }
                        }
                    </td>*@
                        @switch ((ByHand.Services.Code.EOrderStatus)item.Status)
                        {
                            case ByHand.Services.Code.EOrderStatus.Order_BankTransfer_Wait: 
                            <td><span class="label label-warning">@(((ByHand.Services.Code.EOrderStatus)item.Status).ToString().ToLower())</span></td> break;
                            case ByHand.Services.Code.EOrderStatus.Order_COD_Wait: 
                            <td><span class="label label-warning">@(((ByHand.Services.Code.EOrderStatus)item.Status).ToString().ToLower())</span></td> break;
                            case ByHand.Services.Code.EOrderStatus.Order_Done: 
                            <td><span class="label label-success">@(((ByHand.Services.Code.EOrderStatus)item.Status).ToString().ToLower())</span></td> break;
                            case ByHand.Services.Code.EOrderStatus.Order_New: 
                            <td><span class="label label-info">@(((ByHand.Services.Code.EOrderStatus)item.Status).ToString().ToLower())</span></td> break;
                            case ByHand.Services.Code.EOrderStatus.Order_PayFail: 
                            <td><span class="label label-inverse">@(((ByHand.Services.Code.EOrderStatus)item.Status).ToString().ToLower())</span></td> break;
                            case ByHand.Services.Code.EOrderStatus.Order_PaySuccess: 
                            <td><span class="label label-success">@(((ByHand.Services.Code.EOrderStatus)item.Status).ToString().ToLower())</span></td> break;
                            case ByHand.Services.Code.EOrderStatus.Order_WaitDeliver: 
                            <td><span class="label">@(((ByHand.Services.Code.EOrderStatus)item.Status).ToString().ToLower())</span></td> break;
                            case ByHand.Services.Code.EOrderStatus.Order_WaitPay: 
                            <td><span class="label">@(((ByHand.Services.Code.EOrderStatus)item.Status).ToString().ToLower())</span></td> break;
                            case ByHand.Services.Code.EOrderStatus.Order_GuuSuccess: 
                            <td><span class="label label-success">@(((ByHand.Services.Code.EOrderStatus)item.Status).ToString().ToLower())</span></td> break;
                            case ByHand.Services.Code.EOrderStatus.Order_GuuFail: 
                            <td><span class="label label-inverse">@(((ByHand.Services.Code.EOrderStatus)item.Status).ToString().ToLower())</span></td> break;
                        }
                        @*                    <td>
                        @((ByHand.Services.Code.EPayType)item.PayType)
                    </td>*@
                        <td>
                            @(item.RefID)
                        </td>
                        @*                    <td>
                        @(item.RefLocation)
                    </td>*@
                        <td>
                            @(item.BoughtDate.ToString("dd-MM-yyyy hh:mm", cul))
                        </td>
                        <td>
                            @((item.Quantity * item.Price).ToString("#,###", cul.NumberFormat))
                        </td>
                    </tr>
                }
            </tbody>
        </table>
        <div class="pagination">
            <ul>
                @{
                    if (curpage > 1)
                    {
                    <li><a href="/@curcontroller/@curaction/status/@status/pages/@(curpage - 1)/filter/@(isfilter ? ViewData["filter"] : "")">Prev</a></li>
                    }
                    for (int i = 1; i <= total; i++)
                    {
                        if (i != curpage)
                        {
                    <li><a href="/@curcontroller/@curaction/status/@status/pages/@(i)/filter/@(isfilter ? ViewData["filter"] : "")">@i</a></li>
                        }
                        else
                        {
                    <li><a href="/@curcontroller/@curaction/status/@status/pages/@(i)/filter/@(isfilter ? ViewData["filter"] : "")"><strong>@i</strong></a></li>
                        }

                    }
                    if (curpage < total)
                    {
                    <li><a href="/@curcontroller/@curaction/status/@status/pages/@(curpage + 1)/filter/@(isfilter ? ViewData["filter"] : "")">Next</a></li>
                    }
                }
            </ul>
        </div>
    </div>
</div>
<div id="show-detail" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
    <div class="modal-body" style="max-height: none" id="div-content-detail"></div>
</div>
<script src="@Url.Content("~/Content/js/jquery.tablesorter.min.js")"></script>
<script>
    //table sort
    $(function () {
        $("table.sort").tablesorter();
    });
    $("table").bind("sortStart", function () {
    }).bind("sortEnd", function () {
        $('th.header').each(function () {
            if ($(this).hasClass('headerSortDown')) {
                $(this).find('.icon-sort').addClass('icon-hand-up');
                $(this).find('.icon-sort').removeClass('icon-hand-down');

            }
            if ($(this).hasClass('headerSortUp')) {
                $(this).find('.icon-sort').addClass('icon-hand-down');
                $(this).find('.icon-sort').removeClass('icon-hand-up');
            }
            if (!$(this).hasClass('headerSortDown') && !$(this).hasClass('headerSortUp')) {
                $(this).find('.icon-sort').removeClass('icon-hand-down');
                $(this).find('.icon-sort').removeClass('icon-hand-up');
            }
        });
    });
    $(document).ready(function () {
        $('#inputsearch').change(function () {
            var filter = $(this).val();
            $.ajax({
                type: "POST",
                url: '@Url.Action(@tablename, curcontroller)',
                data: { target: 1, page: 1, pagesize: 1, filter: filter, status: '@status' },
                success: function (data) {
                    if (data != null) {
                        var getdata = $(data).find('.table-partial-content');
                        $('.table-partial-content').html(getdata.html());
                    } else {
                    }
                }
            });
        });
        @*$('#form-search').submit(function (e) {
            e.preventDefault();
            var filter = $('#inputsearch').val();
            $.ajax({
                type: "POST",
                url: '@Url.Action(@tablename, curcontroller)',
                data: { target: 1, page: 1, pagesize: 1, filter: filter, status: '@status' },
                success: function (data) {
                    if (data != null) {
                        $('.div-parent').html(data);
                        return false;
                    } else {
                        return false;
                    }
                }
            });
        });*@
    });
    function detail(id) {
        $.post('@Url.Action("Detail", "Order")', { id: id }, function (data) {
            $('#div-content-detail').html(data);
            $('#show-detail').modal({ show: true });
        });
    }
</script>
